﻿namespace FFF.Test.Application.DomainServices.FW
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Abp.Domain.Services;
    using Abp.Domain.Uow;
    using Abp.EntityFrameworkCore.Uow;
    using Abp.EntityFrameworkCore;
    using AutoMapper;
    using Abp.UI;
    using Ydm.Helper;
    using Ydm.Extensions;
    using Microsoft.EntityFrameworkCore;
    using AutoMapper.QueryableExtensions;
    using FFF.Test.DataAccess.Framework;
    using FFF.Test.Application.Repositories.FW;
    using FFF.Test.Entity.FW;
    using FFF.Test.Entity.FW.Dto;
    using FFF.Test.Entity.FW.View;

    /// <summary>
    /// 系统模块中间表领域层服务接口
    /// </summary>
    public class FWApplication2ModuleDomainService : YdmAbpDomainServiceBase, IFWApplication2ModuleDomainService
    {
        /// <summary>
        /// 系统模块中间表仓储
        /// </summary>
        private readonly IFWApplication2ModuleRepository _fWApplication2ModuleRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="FWApplication2ModuleDomainService"/> class.
        /// 系统模块中间表领域层操作
        /// </summary>
        /// <param name="fWApplication2ModuleRepository">系统模块中间表仓储</param>
        /// <param name="dbContextProvider">数据库访问对象</param>
        public FWApplication2ModuleDomainService(
            IFWApplication2ModuleRepository fWApplication2ModuleRepository
        )
        {
            this._fWApplication2ModuleRepository = fWApplication2ModuleRepository;
        }

        /// <summary>
        /// 1.001 获取模块(于大明)
        /// </summary>
        /// <param name="inDto">获取模块输入dto</param>
        /// <returns>获取模块输出dto</returns>
        public async Task<GetMyModuleOutDto> GetMyModuleAsync(GetMyModuleInDto inDto)
        {
            var result = new GetMyModuleOutDto();
            result.Dtos = await this._fWApplication2ModuleRepository.GetView()
                .Where(x => x.ApplicationGUID == inDto.ApplicationGUID)
                .OrderBy(x => x.A2MOrderCode).ProjectTo<GetMyModuleDto>().ToListAsync();
            return result;
        }
    }
}
